/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.dao;

import org.ipti.br.tag.entity.City;
import org.ipti.br.tag.entity.City_;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author israel
 */
@Stateless
public class CityFacade extends AbstractFacade<City> {
    @PersistenceContext(unitName = "TAG2PU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public CityFacade() {
        super(City.class);
    }
    
    @Override
    public void create(City city) {
        String cityHashString = "" + city.getName() + city.getState().getId();
        city.setId(Long.valueOf(EncryptionUtil.encrypt(cityHashString).hashCode()));

        getEntityManager().persist(city);
    }
    
    public List<City> findAllOrder() {
        return findAllOrderBy(City_.name);
    }
    
}
